﻿//**********************************************************
//Copyright(C)2010 By 波特商网公司 版权所有。
//
//文件名：
//文件功能：POS页面框架布局
//
//创建标识：陈博生 || 2011-06-08
//
//修改标识：
//修改描述：
//**********************************************************

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Hmc.IM.Common.Base;
using Hmc.IM.Common.UserControls;
using Hmc.IM.Common.Properties;

namespace Hmc.IM.Common.Forms
{
    /// <summary>
    /// 窗体布局
    /// </summary>
    public partial class PosFrameForm : Form
    {
        /// <summary>
        /// 标题
        /// </summary>
        public string TitleText
        {
            get
            {
                return lblTitle.Text;
            }
            set
            {
                lblTitle.Text = value;
            }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public PosFrameForm()
        {
            InitializeComponent();

            if (DesignMode)
                return;

            //子控件默认不允许透明度颜色，设置透明度颜色前需设置其样式。
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.ImeMode = System.Windows.Forms.ImeMode.KatakanaHalf;
            this.Width = 840;
            this.Height = 434;

            //显示打印和打印预览
            if (this is IPrint)
            {
                linkPrint.Visible = true;
                this.linkPrint.Image = Resources.print;
                linkPrint.Click += new EventHandler(btnPrint_Click);
                this.linkPreview.Visible = true;
                this.linkPreview.Image = Resources.preview;
                linkPreview.Click += new EventHandler(linkPreview_Click);
            }

            //显示导出Excel
            if (this is IExcel)
            {               
                linkExcel.Visible = true;
                this.linkExcel.Image = Resources.lead;
                linkExcel.Click += new EventHandler(btnExcel_Click);
            }
        }

        /// <summary>
        /// 打印预览
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void linkPreview_Click(object sender, EventArgs e)
        {
            IPrint print = this as IPrint;
            print.Preview();
        }
    
        /// <summary>
        /// 导出Excel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnExcel_Click(object sender, EventArgs e)
        {
            IExcel excel = this as IExcel;
            excel.ExportExcel(); 
        }

        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnPrint_Click(object sender, EventArgs e)
        {
            IPrint print = this as IPrint;
            print.Print();
        }

        /// <summary>
        /// 根据权限点判断是否拥有权限
        /// </summary>
        /// <param name="rightID"></param>
        /// <returns></returns>
        public virtual bool IsRight(int rightID)
        {
            var query = from p in LoginUserEntity.PermissionsPoint where p == rightID select p;
            if (query.Count() > 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 验证指定集合控件下的数据格式
        /// </summary>
        /// <param name="controls">需验证的数据集合</param>
        /// <returns></returns>
        public bool CheckValidate(Control controls)
        {
            bool fay = true;
            foreach (Control ctl in controls.Controls)
            {
                if (ctl is ucTextBox)
                {
                    IValidate box = ctl as IValidate;
                    if (!box.Validate())
                    {
                        fay = false;
                    }
                }
                else if (ctl.Controls.Count > 0)
                {
                    CheckValidate(ctl);
                }
            }
            return fay;
        }

        /// <summary>
        /// 验证当前窗体集合下的数据格式
        /// </summary>
        /// <returns></returns>
        public bool CheckValidate()
        {
            return CheckValidate(this);
        }

        private void linkExcel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

        }

        private void linkPreview_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

        }

    }
}
